﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Data;
using System.Data.SqlClient;
using Titan.Runtiming;
using Titan.Data;
using Titan.Logging;
using GaeaWebFramework.Runtime.Core;
using GaeaWebFramework.Runtime.Core.Entities.RightsMmgt;

namespace GaeaWebFramework.Runtime.Core.Services.RightsMmgt
{
    public class RighMgtService : RuntimeService
    {
        #region Fields
        private static String _DBNAME = "Test";
        private SqlHelper sqlhelper = new SqlHelper(_DBNAME);
        private ILogger _logger = new LoggerFactory().GetLogger(typeof(RighMgtService));
        #endregion
        #region Properties
        #endregion
        #region Methods
        public RighMgtService()
        {

        }

        public Users getUser(string username)
        {
            Users result = null;
            result = new Users();
            result.username = username;

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public LoginResult doLogin(string username, string password)
        {
            string sqlstatement = "select * from Users where username=@username";
            SqlParameter[] paramters = new SqlParameter[] { new SqlParameter("username", username) };

            DataSet dataset = sqlhelper.ExecuteDataSetSQL(sqlstatement, paramters);

            if (dataset.Tables[0].Rows.Count == 1)
            {
                if (dataset.Tables[0].Rows[0]["password"] == password)
                {
                    return LoginResult.Succeed;
                }
                else
                {
                    return LoginResult.PasswordWrong;
                }
            }
            else
            {
                return LoginResult.UserNameWrong;
            }
        }

        public List<Users> doGetUsersInGroups(Groups group)
        {
            List<Users> result = new List<Users>();
            return result;
        }

        public List<Users> doGetUserInRoles(Roles role)
        {
        }

        public List<Roles> doGetRolesByUser(Users user)
        {
        }

        public List<Groups> doGetGroupByUser(Users user)
        {
        }
#endregion
        #region events
        #endregion
    }
}
